<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="include/common-header :: common_header(~{::title},~{::link})">
    <title>教职工信息</title>
</head>
<body>

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>列表 </h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <div class="m-l-xs toolbar">
                            <button class="btn btn-sm btn-primary" type="button"
                                    onclick="tteacherinfoListObj.addOrUpdateHandle()"><i
                                    class="fa fa-plus"></i>&nbsp;新增
                            </button>
                            <button id="tteacherinfoList_delAll" class="btn btn-sm btn-danger" type="button"
                                    disabled="disabled"
                                    onclick="tteacherinfoListObj.deleteHandle()"><i
                                    class="fa fa-trash"></i>&nbsp;批量删除
                            </button>
                        </div>
                        <table id="tteacherinfoList_table" class="table table-striped"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<div th:replace="include/common-js :: common_js"></div>
<div th:replace="web/zzsys/tteacherinfo-add-or-update::tteacherinfoAddOrUpdate"></div>
<script type="text/javascript">
    $().ready(function () {
        tteacherinfoListObj.initTable();
    })
    var tteacherinfoListObj = new Object({
        dataListSelections: [],
        myTable: undefined,
        addOrUpdateHandle: function (id) {
            tteacherinfoAddOrUpdateObj.init(id);
            $('#tteacherinfoAddOrUpdate_Modal').modal('show')
        },
        deleteHandle: function (id) {
            let ids = id ? [id] :
                this.dataListSelections.map(item => {
                    return item.roleId;
                });
            $.mySwalConfirm(`将\$\{id ? '删除' : '批量删除'\}，确认吗？`, function () {
                $.myPost({
                    url: `/zzsys/tteacherinfo/delete/${id}`,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            tteacherinfoListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        checkRowHander: function () {
            tteacherinfoListObj.dataListSelections = tteacherinfoListObj.myTable.bootstrapTable('getSelections');
            if (tteacherinfoListObj.dataListSelections.length > 0) {
                $('#tteacherinfoList_delAll').removeAttr("disabled");
            } else {
                $('#tteacherinfoList_delAll').attr("disabled", "disabled");
            }
        },
        refreshDataList: function () {
            tteacherinfoListObj.myTable.bootstrapTable('refresh');
        },
        initTable: function () {
            tteacherinfoListObj.myTable = $('#tteacherinfoList_table').bootstrapTable({
                toolbar: ".toolbar",
                search: true,
                trimOnSearch: true,
                pagination: true,
                sidePagination: 'server',
                url: '/zzsys/teacher/list',
                method: 'post',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    param.hasSign = true;
                    return param;
                },
                onCheck: function (row, $element) {
                    tteacherinfoListObj.checkRowHander();
                },
                onUncheck: function (row, $element) {
                    tteacherinfoListObj.checkRowHander();
                },
                onCheckAll: function (row, $element) {
                    tteacherinfoListObj.checkRowHander();
                },
                onUncheckAll: function (row, $element) {
                    tteacherinfoListObj.checkRowHander();
                },
                onCheckSome: function (row) {
                    tteacherinfoListObj.checkRowHander();
                },
                onUncheckSome: function (row) {
                    tteacherinfoListObj.checkRowHander();
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    checkbox: true,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '工号',
                    field: 'workNo',
                    sortable: true,
                    sortName: 'WORK_NO_',
                    width: 100
                }, {
                    title: '姓名',
                    field: 'name',
                    width: 100
                }, {
                    title: '签章',
                    field: 'signImgPath',
                    formatter(value, row, index){
                        if(value){
                            let str = `<img src='${row.confirmImgViewPath}'>`;
                            return str;
                        }
                        return value;
                    }
                }, {
                    title: '签章（确认）',
                    field: 'confirmImgPath',
                    formatter(value, row, index){
                        if(value){
                            let str = `<img src='${row.signImgViewPath}'>`;
                            return str;
                        }
                        return value;
                    }
                }, {
                    title: '操作',
                    align: 'center',
                    width: 100,
                    events: {
                        'click .edit': function (e, value, row, index) {
                            tteacherinfoListObj.addOrUpdateHandle(row.id)
                        },
                        'click .trash': function (e, value, row, index) {
                            tteacherinfoListObj.deleteHandle(row.id)
                        }
                    },
                    formatter: function (value, row, index) {
                        var opers = [];
                        opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                        opers.push(`<a class="trash btn btn-white btn-bitbucket text-info" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                        return opers.join('');
                    }
                }],
                responseHandler: function (res) {
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                },
                onLoadSuccess: function (data) {
                    $('[data-toggle="tooltip"]').tooltip()
                }
            });
        }
    })
</script>
</body>
</html>